<?php
namespace Member\Controller;
use Think\Controller;
class BaseController extends Controller {
   function _initialize(){
        if(session('member')===null){
           $this->redirect('Reg/login');
        }else{
           // $this->rootCheck();
        }
   }
    protected function rootCheck(){
        $department_id=M("Member")->where(array('username'=>session('member')))->getField('department_id');
        $m = M('DepartmentMember');
        $root_group_id=$m->where(array('id'=>$department_id))->getField('root_group_id');
        $m = M('RootMember');
        $a_id=$m->where(array('controller'=>CONTROLLER_NAME))->getField('action,id',true);
        $group_id=explode(',',$root_group_id);
        $no_arr=array(//额外的都具备的权限
            'Index'=>array('index','welcome'),
            // 'Role'=>array('getDepartment','getRole','getEditRole'),
        );
        foreach($a_id as $k=>$v){
            $key=explode(',',$k);
            if($key[0]==ACTION_NAME || $key[1]==ACTION_NAME){
                $root_id=$v;
            }
        }
        if(!in_array($root_id,$group_id)){
            if(!in_array(ACTION_NAME,$no_arr[CONTROLLER_NAME])){
                alert(0,'没有权限');
            }
        }
    }
}